/***************************************************************************
* Lyrics-Player                                                            *
* Copyright (C) 2012 Andrey Derevyanko <derandr@gmail.com>                 *
*                                                                          *
* This program is free software: you can redistribute it and/or modify     *
* it under the terms of the GNU General Public License as published by     *
* the Free Software Foundation, either version 3 of the License, or        *
* (at your option) any later version.                                      *
*                                                                          *
* This program is distributed in the hope that it will be useful,          *
* but WITHOUT ANY WARRANTY; without even the implied warranty of           *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
* GNU General Public License for more details.                             *
*                                                                          *
* You should have received a copy of the GNU General Public License        *
* along with this program.  If not, see <http://www.gnu.org/licenses/>.    *
***************************************************************************/

/*! \file id3Lib.h
 *  \brief Functions for metadata access using id3 library declaration
 *  \details Namespace contains reader and writer access classes with the corresponding functions
 *  \author Andrey Derevyanko <derandr@gmail.com>
 *  \version 1.0
 *  \date 15/10/2012
 *  \copyright GNU Public License
 */

#ifndef ID3LIB_H
#define ID3LIB_H

#include <QObject>
#include <QString>
#include <id3/misc_support.h>

#include "sharedStructures.h"

namespace id3Lib{

/*! \class id3Reader
 *  \brief Metada reader class using id3 library
 */
class id3Reader : public QObject{
     Q_OBJECT
public:
    //! Constructor
    id3Reader();
    //! Destructor
    ~id3Reader();
public slots:
    /*! \fn void newSourceFile(QString fileName)
     *  \brief New sourse file is selected to read metadata
     *  \param fileName File path in the file system
     */
    void newSourceFile(QString fileName);
signals:
    /*! \fn void newMetaData(trackMetaData_t data)
     *  \brief Metadata were read from the file
     *  \param data Structure containing metadata
     */
    void newMetaData(trackMetaData_t data);
private:
    //QString readTagField(ID3Tag *tag, ID3_FrameID id);
};

/*! \class id3Reader
 *  \brief Metada writer class using id3 library
 */
class id3Writer : public QObject{
     Q_OBJECT
public:
    //! Constructor
    id3Writer();
    //! Destructor
    ~id3Writer();
public slots:
    /*! \fn void setMetaData(QString fileName, trackMetaData_t data)
     *  \brief Function to write matadata to the file
     *  \param fileName File path in the file system
     *  \param data Structure containing metadata
     */
    void setMetaData(QString fileName, trackMetaData_t data);
};

/*! \class id3TagConverter
 *  \brief Class containing static functions of tags converting
 */
class id3TagConverter {
public:
    //! Constructor
    id3TagConverter(){}
    //! Destructor
    ~id3TagConverter(){}
    /*! \fn static QString numToGenre(quint8 genNumber)
     *  \brief Function transforming genre number to its name
     *  \param genNumber Genre number
     */
    static QString numToGenre(quint8 genNumber){
        return genreDescription[genNumber];
    }
    /*! \fn static quint8 genreToNum(QString genName)
     *  \brief Function transforming genre name to its number
     *  \param genName Genre name
     */
    static quint8 genreToNum(QString genName){
        for (quint8 i = 0; i < number_of_genres; i++){
            if (genreDescription[i] == genName)
                return i;
        }
        return 255;
    }

private:
    static const quint8 number_of_genres = 148; //!< Number of genres
    static const QString genreDescription[number_of_genres]; //!< Array of genre names
};

}

#endif // ID3LIB_H
